{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "import os\n",
    "import datetime\n",
    "from sklearn import preprocessing\n",
    "os.chdir(\"C:/Users/Ma/Desktop/document/企业经营退出风险预测/analysis\")\n",
    "\n",
    "# data = pd.read_csv('data.csv',encoding='gb2312')\n",
    "entbase = pd.read_csv('1entbase.csv',encoding='gb2312')\n",
    "alter = pd.read_csv('2alter.csv',encoding='utf8')\n",
    "branch = pd.read_csv('3branch.csv',encoding='gb2312')\n",
    "invest = pd.read_csv('4invest.csv',encoding='gb2312')\n",
    "right = pd.read_csv('5right.csv',encoding='gb2312')\n",
    "project = pd.read_csv('6project.csv',encoding='gb2312')\n",
    "lawsuit = pd.read_csv('7lawsuit.csv',encoding='gb2312')\n",
    "breakfaith = pd.read_csv('8breakfaith.csv',encoding='gb2312')\n",
    "recruit = pd.read_csv('9recruit.csv',encoding='gb2312')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "# 企业基本信息"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>EID</th>\n",
       "      <th>RGYEAR</th>\n",
       "      <th>HY</th>\n",
       "      <th>ZCZB</th>\n",
       "      <th>ETYPE</th>\n",
       "      <th>MPNUM</th>\n",
       "      <th>INUM</th>\n",
       "      <th>FINZB</th>\n",
       "      <th>FSTINUM</th>\n",
       "      <th>TZINUM</th>\n",
       "      <th>num</th>\n",
       "      <th>hyty</th>\n",
       "      <th>year_imp</th>\n",
       "      <th>id_imp</th>\n",
       "      <th>old</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>32741</td>\n",
       "      <td>2000</td>\n",
       "      <td>87</td>\n",
       "      <td>100.0</td>\n",
       "      <td>7</td>\n",
       "      <td>1.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>877</td>\n",
       "      <td>0.020000</td>\n",
       "      <td>0.000031</td>\n",
       "      <td>16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>294220</td>\n",
       "      <td>2003</td>\n",
       "      <td>51</td>\n",
       "      <td>50.0</td>\n",
       "      <td>7</td>\n",
       "      <td>0.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>517</td>\n",
       "      <td>0.018868</td>\n",
       "      <td>0.000003</td>\n",
       "      <td>13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>10526</td>\n",
       "      <td>2013</td>\n",
       "      <td>75</td>\n",
       "      <td>100.0</td>\n",
       "      <td>7</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>757</td>\n",
       "      <td>0.015873</td>\n",
       "      <td>0.000095</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>237382</td>\n",
       "      <td>2014</td>\n",
       "      <td>75</td>\n",
       "      <td>9900.0</td>\n",
       "      <td>7</td>\n",
       "      <td>3.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>11.0</td>\n",
       "      <td>757</td>\n",
       "      <td>0.015625</td>\n",
       "      <td>0.000004</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>473535</td>\n",
       "      <td>2008</td>\n",
       "      <td>75</td>\n",
       "      <td>50.0</td>\n",
       "      <td>7</td>\n",
       "      <td>3.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>10.0</td>\n",
       "      <td>757</td>\n",
       "      <td>0.017241</td>\n",
       "      <td>0.000002</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      EID  RGYEAR  HY    ZCZB  ETYPE  MPNUM  INUM  FINZB  FSTINUM  TZINUM  \\\n",
       "0   32741    2000  87   100.0      7    1.0   3.0    0.0      2.0     0.0   \n",
       "1  294220    2003  51    50.0      7    0.0   3.0    0.0      0.0     0.0   \n",
       "2   10526    2013  75   100.0      7    1.0   2.0    0.0      1.0     0.0   \n",
       "3  237382    2014  75  9900.0      7    3.0   4.0    0.0      2.0     0.0   \n",
       "4  473535    2008  75    50.0      7    3.0   5.0    0.0      1.0     0.0   \n",
       "\n",
       "    num  hyty  year_imp    id_imp  old  \n",
       "0   8.0   877  0.020000  0.000031   16  \n",
       "1   3.0   517  0.018868  0.000003   13  \n",
       "2   5.0   757  0.015873  0.000095    3  \n",
       "3  11.0   757  0.015625  0.000004    2  \n",
       "4  10.0   757  0.017241  0.000002    8  "
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# ----------------------------------------------------注册资本缺失值填充-----------------------------------------------#\n",
    "# scaler = preprocessing.MinMaxScaler()\n",
    "entbase['ZCZB']=entbase['ZCZB'].groupby([entbase.ETYPE,entbase.HY]).apply(lambda g:g.fillna(g.mean()))\n",
    "entbase['MPNUM'] = entbase['MPNUM'].fillna(0)\n",
    "# entbase['MPNUM'] = scaler.fit_transform(entbase.MPNUM)\n",
    "entbase['INUM'] = entbase['INUM'].fillna(0)\n",
    "entbase['FINZB'] = entbase['FINZB'].fillna(0)\n",
    "entbase['FSTINUM'] = entbase['FSTINUM'].fillna(0)\n",
    "entbase['TZINUM'] = entbase['TZINUM'].fillna(0)\n",
    "#-------------------------------------------------------构造新特征-------------------------------------------------------#\n",
    "entbase['num'] = entbase['MPNUM']+ entbase['INUM']+entbase['FINZB']+entbase['FSTINUM']+entbase['FSTINUM']+entbase['TZINUM']\n",
    "entbase['hyty'] = (entbase.HY.astype('str') + entbase.ETYPE.astype('str')).astype('int')\n",
    "entbase['year_imp']= 1/(entbase['RGYEAR'] - entbase.RGYEAR.min()+1)\n",
    "entbase['id_imp']= 1/(entbase['EID'] - entbase.EID.min()+1)\n",
    "entbase['old'] = 2016 - entbase.RGYEAR\n",
    "# entbase['ZB'] = entbase.ZCZB + entbase.FINZB\n",
    "data = entbase\n",
    "data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# 保存训练集\n",
    "train = pd.read_csv('train.csv',encoding='gb2312')\n",
    "data_train = pd.merge(left=train,right=data,left_on='EID',right_on='EID',how='left')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>EID</th>\n",
       "      <th>TARGET</th>\n",
       "      <th>RGYEAR</th>\n",
       "      <th>HY</th>\n",
       "      <th>ZCZB</th>\n",
       "      <th>ETYPE</th>\n",
       "      <th>MPNUM</th>\n",
       "      <th>INUM</th>\n",
       "      <th>FINZB</th>\n",
       "      <th>FSTINUM</th>\n",
       "      <th>TZINUM</th>\n",
       "      <th>num</th>\n",
       "      <th>hyty</th>\n",
       "      <th>year_imp</th>\n",
       "      <th>id_imp</th>\n",
       "      <th>old</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>309</td>\n",
       "      <td>0</td>\n",
       "      <td>2001</td>\n",
       "      <td>87</td>\n",
       "      <td>10.0</td>\n",
       "      <td>17</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>8717</td>\n",
       "      <td>0.019608</td>\n",
       "      <td>0.003236</td>\n",
       "      <td>15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>356</td>\n",
       "      <td>0</td>\n",
       "      <td>2011</td>\n",
       "      <td>50</td>\n",
       "      <td>100.0</td>\n",
       "      <td>7</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>507</td>\n",
       "      <td>0.016393</td>\n",
       "      <td>0.002809</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>383</td>\n",
       "      <td>0</td>\n",
       "      <td>1999</td>\n",
       "      <td>43</td>\n",
       "      <td>3.0</td>\n",
       "      <td>17</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>4317</td>\n",
       "      <td>0.020408</td>\n",
       "      <td>0.002611</td>\n",
       "      <td>17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>399</td>\n",
       "      <td>0</td>\n",
       "      <td>2011</td>\n",
       "      <td>75</td>\n",
       "      <td>50.0</td>\n",
       "      <td>7</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>757</td>\n",
       "      <td>0.016393</td>\n",
       "      <td>0.002506</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>619</td>\n",
       "      <td>0</td>\n",
       "      <td>2008</td>\n",
       "      <td>74</td>\n",
       "      <td>200.0</td>\n",
       "      <td>7</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>747</td>\n",
       "      <td>0.017241</td>\n",
       "      <td>0.001616</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   EID  TARGET  RGYEAR  HY   ZCZB  ETYPE  MPNUM  INUM  FINZB  FSTINUM  TZINUM  \\\n",
       "0  309       0    2001  87   10.0     17    0.0   2.0    0.0      0.0     0.0   \n",
       "1  356       0    2011  50  100.0      7    0.0   1.0    0.0      0.0     0.0   \n",
       "2  383       0    1999  43    3.0     17    1.0   2.0    0.0      1.0     0.0   \n",
       "3  399       0    2011  75   50.0      7    1.0   1.0    0.0      0.0     0.0   \n",
       "4  619       0    2008  74  200.0      7    0.0   2.0    0.0      0.0     0.0   \n",
       "\n",
       "   num  hyty  year_imp    id_imp  old  \n",
       "0  2.0  8717  0.019608  0.003236   15  \n",
       "1  1.0   507  0.016393  0.002809    5  \n",
       "2  5.0  4317  0.020408  0.002611   17  \n",
       "3  2.0   757  0.016393  0.002506    5  \n",
       "4  2.0   747  0.017241  0.001616    8  "
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_train.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 降维可视化，企图发现一些离群点"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\ProgramData\\Anaconda3\\lib\\site-packages\\matplotlib\\axes\\_axes.py:545: UserWarning: No labelled objects found. Use label='...' kwarg on individual plots.\n",
      "  warnings.warn(\"No labelled objects found. \"\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAtQAAAHqCAYAAAAktdmwAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3Xm4nWV9L/zvL3MgBILEYBywWJwRLRtFxBIHXsX2aKFW\n69B61JYOtj19e05brZwe9VjP2+HYweNES3vUqi212qp1qBYpUbR1pwo44MyogSCBCGTe9/vHXpiE\n7Ozs7HuP5vO5rnVlrd+6171+6772Xuu7nzzreaq1FgAAYHIWzHYDAAAwnwnUAADQQaAGAIAOAjUA\nAHQQqAEAoINADQAAHQRqgA5V9Z+ramtV3VRV36mq39nrvrOr6ltVdV1Vvewej3tnVf3vKXj+n6+q\nGwbPf+YhPO6aqnpg7/MDIFADTIV/bK2tSXJykhdV1RlVtSrJXyd5bpJHJvl/q+qhez3myYNLrz9I\n8vgk90ty5RTM931VdUxV/fpUzjmT8wPMFIEaYIq01m5J8sEkT0zyrCSfba39e2ttS5KPJ3lSklTV\nI5Jcl+SYqjqu82mPaa1d31rbOXieqXRMkukMvNM9P8CMEKgBplYlGcnoVumv7FV/XZL3D64/Ocml\nSdZnELLHnbDqNwe7jXylqs4Z1H6/qjYOrm+sqi8eZI4FVfXmwW4p70yyeK/7Xl1VNw6e42cGtXcl\n+WyS+w/m/8h44/eqf3vwHL+8V/3FVfXVqrq+qn7+YPMDzDcCNcAUqar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t3915\nVO7590olecDye+V7u7Zl++6d2Z2WHSM705K0wZg1y47On5764px41L3H7GD4c9/K77z6vdmxcyT3\nPu6ovOPCF2fp0qXZuXN3/vmSL+b9H74i27btyJIli7JyxdKsXr0yn/z017Jz5+48/rEPyqte8azv\nz3XR29fnPf84nJbkvB9/TJ79gkfmXde+JZt33JIfXvHwPOd+L83ChQvHXZFbtt+cP/nq7+aOXVuy\nMIvywhN+IY859gnjPubGrdfm6i1XZtfIjnx76/XZPrItpx77hJx27BPHfdyXN96cT33zuqxYuiRP\ne9hJWXXE8v3GbN25M7/47n/M1TdvyvErj8pbnvPM3OeYlePOOxvazi8lOy5PakWy7OmpBccc2uN3\nb0y2fTTJrmTpk1KLTpyeRpmXPnHDN/OHw/+a3a3lZaecnmee+PApnf+bt9+aS274RpYtXJSnn/Dg\nHLf8yCmd/3Cwe/dINqz/aq775s15wIn3zqlPfHAWLrSNC/a26bY78r5PfSHXb7otp550vzzttIdk\n+ZLFs93WmKq1dvBRM6CqLkrysCQfaq299kDjhoaG2vDw8Iz0dPaCn9rr1r7rtHBJy89+5Js55oTR\no320lty2c3kuuu6J2T6yKDvb3UF0cofXe+kPPSm/8JCz96n9xu/8TTZ8/rr9xv7+a34yr/ujD+X2\nLVsnNPdH3/tredbz3pRt23ftVW057gk3577nfDt3HxGwUnnVI/5Pjlly7JjzfOaWS/Pu69+6X/1+\nyx6Y33zY/9qv3lrL313/l/n3Wy/LrrYz7R5reuzi1bng4X+chQsW7ve4Cz748XzwC1dn18hIFg8+\ndN74nGfmCSee8P1xX7jxpvzkX75rv+f9H09/Up5/2qPHfA0zrbWWtuWVydYPJtmVZPSNoVa9KbV0\n/D9E7jZy1z8kW/773beSLEiO/LksOOq/TEfLzDM/9U/vzGdvvnGf2okrj80lP/lzUzL/H264LH/x\nxeG01rKwKi3Jn/zoj+XpD3zIlMx/OLh98535r89/S269eUt27NiVJUsW5dh7r8z/ftcv5uhV/jiB\nJLnym9/JL//Z32fX7pHs2LU7y5csz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/w8a+CSs5uAGIQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x1afd47e1b70>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from sklearn.cluster import KMeans\n",
    "import matplotlib.pyplot as plt\n",
    "from sklearn.decomposition import PCA,KernelPCA\n",
    "from sklearn.preprocessing import StandardScaler,RobustScaler\n",
    "\n",
    "train = data_train.drop('TARGET',axis=1)\n",
    "train = np.array(train)\n",
    "labels = data_train.TARGET\n",
    "# 标准化\n",
    "# scaler = StandardScaler()\n",
    "scaler = RobustScaler()\n",
    "train = scaler.fit_transform(train)\n",
    "y_pred = KMeans(n_clusters=10).fit_predict(train)\n",
    "# kpca = KernelPCA(eigen_solver='arpack',n_components=2)\n",
    "\n",
    "# X_kpca = kpca.fit_transform(train)\n",
    "\n",
    "pca = PCA(n_components=2)\n",
    "X_r = pca.fit_transform(train)\n",
    "\n",
    "plt.figure()\n",
    "plt.scatter(X_r[:,0], X_r[:,1],c=y_pred)\n",
    "plt.legend()\n",
    "plt.title('PCA of dataset')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    1.0\n",
       "Name: TARGET, dtype: float64"
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "i = 7\n",
    "data_train['TARGET'][y_pred==i].value_counts()/data_train['TARGET'][y_pred==i].shape[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 136,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# plt.figure(figsize=(6,4))\n",
    "# plt.hist(entbase.ZCZB,range=(entbase.ZCZB.min(),1000),bins=100)\n",
    "# plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 企业变更"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>EID</th>\n",
       "      <th>ALTERNO</th>\n",
       "      <th>ALTDATE</th>\n",
       "      <th>ALTBE</th>\n",
       "      <th>ALTAF</th>\n",
       "      <th>alter_year</th>\n",
       "      <th>alter_month</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>350</td>\n",
       "      <td>12</td>\n",
       "      <td>2015-02</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2015</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>399</td>\n",
       "      <td>05</td>\n",
       "      <td>2014-01</td>\n",
       "      <td>10</td>\n",
       "      <td>50</td>\n",
       "      <td>2014</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>399</td>\n",
       "      <td>12</td>\n",
       "      <td>2015-05</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2015</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>399</td>\n",
       "      <td>12</td>\n",
       "      <td>2013-12</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2013</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>399</td>\n",
       "      <td>27</td>\n",
       "      <td>2014-01</td>\n",
       "      <td>10</td>\n",
       "      <td>50</td>\n",
       "      <td>2014</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   EID ALTERNO  ALTDATE ALTBE ALTAF  alter_year  alter_month\n",
       "0  350      12  2015-02   NaN   NaN        2015            2\n",
       "1  399      05  2014-01    10    50        2014            1\n",
       "2  399      12  2015-05   NaN   NaN        2015            5\n",
       "3  399      12  2013-12   NaN   NaN        2013           12\n",
       "4  399      27  2014-01    10    50        2014            1"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# alter = pd.read_csv('2alter.csv',encoding='utf8')\n",
    "alter.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\ProgramData\\Anaconda3\\lib\\site-packages\\ipykernel\\__main__.py:29: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame\n",
      "\n",
      "See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>EID</th>\n",
       "      <th>RGYEAR</th>\n",
       "      <th>HY</th>\n",
       "      <th>ZCZB</th>\n",
       "      <th>ETYPE</th>\n",
       "      <th>MPNUM</th>\n",
       "      <th>INUM</th>\n",
       "      <th>FINZB</th>\n",
       "      <th>FSTINUM</th>\n",
       "      <th>TZINUM</th>\n",
       "      <th>...</th>\n",
       "      <th>1year12</th>\n",
       "      <th>1year13</th>\n",
       "      <th>1year14</th>\n",
       "      <th>1year27</th>\n",
       "      <th>1year99</th>\n",
       "      <th>1yearA_015</th>\n",
       "      <th>1yearalter_1total</th>\n",
       "      <th>alter_if</th>\n",
       "      <th>alter_year_impor</th>\n",
       "      <th>ori_zb</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>32741</td>\n",
       "      <td>2000</td>\n",
       "      <td>87</td>\n",
       "      <td>100.0</td>\n",
       "      <td>7</td>\n",
       "      <td>1.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>100.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>294220</td>\n",
       "      <td>2003</td>\n",
       "      <td>51</td>\n",
       "      <td>50.0</td>\n",
       "      <td>7</td>\n",
       "      <td>0.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>50.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>10526</td>\n",
       "      <td>2013</td>\n",
       "      <td>75</td>\n",
       "      <td>100.0</td>\n",
       "      <td>7</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>100.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>237382</td>\n",
       "      <td>2014</td>\n",
       "      <td>75</td>\n",
       "      <td>9900.0</td>\n",
       "      <td>7</td>\n",
       "      <td>3.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>9900.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>473535</td>\n",
       "      <td>2008</td>\n",
       "      <td>75</td>\n",
       "      <td>50.0</td>\n",
       "      <td>7</td>\n",
       "      <td>3.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>50.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 46 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      EID  RGYEAR  HY    ZCZB  ETYPE  MPNUM  INUM  FINZB  FSTINUM  TZINUM  \\\n",
       "0   32741    2000  87   100.0      7    1.0   3.0    0.0      2.0     0.0   \n",
       "1  294220    2003  51    50.0      7    0.0   3.0    0.0      0.0     0.0   \n",
       "2   10526    2013  75   100.0      7    1.0   2.0    0.0      1.0     0.0   \n",
       "3  237382    2014  75  9900.0      7    3.0   4.0    0.0      2.0     0.0   \n",
       "4  473535    2008  75    50.0      7    3.0   5.0    0.0      1.0     0.0   \n",
       "\n",
       "    ...    1year12  1year13  1year14  1year27  1year99  1yearA_015  \\\n",
       "0   ...        0.0      0.0      0.0      0.0      0.0         0.0   \n",
       "1   ...        0.0      0.0      0.0      0.0      0.0         0.0   \n",
       "2   ...        0.0      0.0      0.0      0.0      0.0         0.0   \n",
       "3   ...        0.0      0.0      0.0      0.0      0.0         0.0   \n",
       "4   ...        0.0      0.0      0.0      0.0      0.0         0.0   \n",
       "\n",
       "   1yearalter_1total  alter_if  alter_year_impor  ori_zb  \n",
       "0                0.0         0               0.0   100.0  \n",
       "1                0.0         0               0.0    50.0  \n",
       "2                0.0         0               0.0   100.0  \n",
       "3                0.0         0               0.0  9900.0  \n",
       "4                0.0         0               0.0    50.0  \n",
       "\n",
       "[5 rows x 46 columns]"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "alter = pd.read_csv('2alter.csv',encoding='utf8')\n",
    "#---------------------------------------------------------数据清洗以及特征构造----------------------------------------------------#\n",
    "\n",
    "# --------------------------------------------------------去重，有很多重复的------------------------------------------------------#\n",
    "alter.drop_duplicates(inplace=True)\n",
    "\n",
    "# ----------------------------------------------------去除字符中的万元和小数点---------------------------------------------------#\n",
    "alter.ALTBE = alter.ALTBE.astype('str')\n",
    "alter.ALTBE = alter.ALTBE.apply(lambda x :x.strip('万元').split('.')[0] if ~pd.isnull(x) else x)\n",
    "alter.ALTAF = alter.ALTAF.astype('str')\n",
    "alter.ALTAF = alter.ALTAF.apply(lambda x :x.strip('万元').split('.')[0] if ~pd.isnull(x) else x)\n",
    "\n",
    "# ----------------------------------------------------变动年 和 月-------------------------------------------------------------#\n",
    "alter['alter_year'] = alter.ALTDATE.apply(lambda x : x.split('-')[0]).astype('int')\n",
    "alter['alter_month'] = alter.ALTDATE.apply(lambda x : x.split('-')[1]).astype('int')\n",
    "# 是否最近一年(2015年)变动\n",
    "alter['alter_1year'] = np.where(alter.alter_year>2014,1,0)\n",
    "# 企业每个类型的变化次数（所有年份）\n",
    "alter_num = alter.groupby(['EID','ALTERNO'],as_index=False).agg({'ALTDATE':'count'}).pivot('EID','ALTERNO','ALTDATE').fillna(0)\n",
    "alter_num['alter_total'] = alter_num.apply(lambda x :x.sum(),axis=1)\n",
    "# -------------------------------------------------企业每个类型的变化次数（近一年）---------------------------------------------#\n",
    "alter_num1 = alter.groupby(['EID','ALTERNO'],as_index=False).agg({'alter_1year':'sum'}).pivot('EID','ALTERNO','alter_1year').fillna(0)\n",
    "alter_num1['alter_1total'] = alter_num1.apply(lambda x :x.sum(),axis=1)\n",
    "alter_num1.rename(columns=lambda x :'1year'+str(x),inplace=True)\n",
    "# ------------------------------------------------变动年份的权重，越近，权重越大-------------------------------------------------#\n",
    "alter['alter_year_impor'] = (1/(1+alter['alter_year']-alter['alter_year'].min())).fillna(0)\n",
    "alter_year_impor = alter.groupby('EID').agg({'alter_year_impor':'mean'})\n",
    "\n",
    "\n",
    "# ----------------------------------------------------增加新特征，资本变动差------------------------------------------------------#\n",
    "alter.ALTBE[alter.ALTBE == 'null'] = np.nan\n",
    "alter.ALTAF = alter.ALTAF.apply(lambda x : float(x) if ~pd.isnull(x) else x)\n",
    "alter.ALTBE = alter.ALTBE.apply(lambda x : float(x) if ~pd.isnull(x) else x)\n",
    "alter['alter_zczb'] = (alter.ALTAF - alter.ALTBE)\n",
    "\n",
    "# 只挑选变动为5的企业，并且最近变动的，去重,\n",
    "alter_5 = alter.loc[alter.ALTERNO == '05'][['EID','alter_zczb','alter_year','alter_month']]\n",
    "alter_5.sort_values(by=['alter_year','alter_month'],inplace=True,ascending=False)\n",
    "alter_5.drop_duplicates('EID',inplace=True)\n",
    "del(alter_5['alter_month'])\n",
    "# del(alter_5['alter_year'])\n",
    "# 还有挑选出企业的原始资本\n",
    "alter_ori_zb = alter.loc[alter.ALTERNO == '05'][['EID','ALTBE','alter_year','alter_month']]\n",
    "alter_ori_zb.sort_values(by=['alter_year','alter_month'],ascending=True,inplace=True)\n",
    "alter_ori_zb.drop_duplicates('EID',inplace=True)\n",
    "alter_ori_zb.rename(columns={'ALTBE':'ori_zb'},inplace=True)\n",
    "del(alter_ori_zb['alter_year'])\n",
    "del(alter_ori_zb['alter_month'])\n",
    "\n",
    "# ------------------------------------------------------合并----------------------------------------------------------------#\n",
    "# 资本变动的表\n",
    "data = pd.merge(left=data,right=alter_5,left_on='EID',right_on='EID',how='left')\n",
    "data['alter_zczb'].fillna(0,inplace=True)\n",
    "data['alter_year'].fillna(2016,inplace=True)\n",
    "# 变动数量的表\n",
    "data = pd.merge(left=data,right=alter_num,left_on='EID',right_index=True,how='left').fillna(0)\n",
    "# 近一年变动\n",
    "data = pd.merge(left=data,right=alter_num1,left_on='EID',right_index=True,how='left').fillna(0)\n",
    "# 判断是否有变动的特征\n",
    "data['alter_if'] = np.where(data.alter_total>0,1,0)\n",
    "# 变动年份的重要性\n",
    "data = pd.merge(left=data,right=alter_year_impor,left_on='EID',right_index=True,how='left').fillna(0)\n",
    "# 原始资本表\n",
    "data = pd.merge(left=data,right=alter_ori_zb,left_on='EID',right_on='EID',how='left')\n",
    "data['ori_zb'].fillna(data['ZCZB'],inplace=True)\n",
    "data.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 企业分支机构"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>EID</th>\n",
       "      <th>TYPECODE</th>\n",
       "      <th>IFHOME</th>\n",
       "      <th>B_REYEAR</th>\n",
       "      <th>B_ENDYEAR</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>405460</td>\n",
       "      <td>br120022</td>\n",
       "      <td>0</td>\n",
       "      <td>1993</td>\n",
       "      <td>2008.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>138728</td>\n",
       "      <td>br210454</td>\n",
       "      <td>1</td>\n",
       "      <td>2002</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>405460</td>\n",
       "      <td>br60051</td>\n",
       "      <td>0</td>\n",
       "      <td>2011</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>247652</td>\n",
       "      <td>br210455</td>\n",
       "      <td>1</td>\n",
       "      <td>2014</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>26268</td>\n",
       "      <td>br30155</td>\n",
       "      <td>0</td>\n",
       "      <td>2014</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      EID  TYPECODE  IFHOME  B_REYEAR  B_ENDYEAR\n",
       "0  405460  br120022       0      1993     2008.0\n",
       "1  138728  br210454       1      2002        NaN\n",
       "2  405460   br60051       0      2011        NaN\n",
       "3  247652  br210455       1      2014        NaN\n",
       "4   26268   br30155       0      2014        NaN"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "branch = pd.read_csv('3branch.csv',encoding='gb2312')\n",
    "branch.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# branch.B_REYEAR.value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>EID</th>\n",
       "      <th>RGYEAR</th>\n",
       "      <th>HY</th>\n",
       "      <th>ZCZB</th>\n",
       "      <th>ETYPE</th>\n",
       "      <th>MPNUM</th>\n",
       "      <th>INUM</th>\n",
       "      <th>FINZB</th>\n",
       "      <th>FSTINUM</th>\n",
       "      <th>TZINUM</th>\n",
       "      <th>...</th>\n",
       "      <th>B_ENDYEAR</th>\n",
       "      <th>branch_old</th>\n",
       "      <th>0_x_y</th>\n",
       "      <th>1_x_y</th>\n",
       "      <th>bra_1total</th>\n",
       "      <th>0_y_y</th>\n",
       "      <th>1_y_y</th>\n",
       "      <th>bra_end_1total</th>\n",
       "      <th>bra_pro1</th>\n",
       "      <th>branh_if</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>32741</td>\n",
       "      <td>2000</td>\n",
       "      <td>87</td>\n",
       "      <td>100.0</td>\n",
       "      <td>7</td>\n",
       "      <td>1.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>294220</td>\n",
       "      <td>2003</td>\n",
       "      <td>51</td>\n",
       "      <td>50.0</td>\n",
       "      <td>7</td>\n",
       "      <td>0.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>10526</td>\n",
       "      <td>2013</td>\n",
       "      <td>75</td>\n",
       "      <td>100.0</td>\n",
       "      <td>7</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>237382</td>\n",
       "      <td>2014</td>\n",
       "      <td>75</td>\n",
       "      <td>9900.0</td>\n",
       "      <td>7</td>\n",
       "      <td>3.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>473535</td>\n",
       "      <td>2008</td>\n",
       "      <td>75</td>\n",
       "      <td>50.0</td>\n",
       "      <td>7</td>\n",
       "      <td>3.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>2012.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 65 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      EID  RGYEAR  HY    ZCZB  ETYPE  MPNUM  INUM  FINZB  FSTINUM  TZINUM  \\\n",
       "0   32741    2000  87   100.0      7    1.0   3.0    0.0      2.0     0.0   \n",
       "1  294220    2003  51    50.0      7    0.0   3.0    0.0      0.0     0.0   \n",
       "2   10526    2013  75   100.0      7    1.0   2.0    0.0      1.0     0.0   \n",
       "3  237382    2014  75  9900.0      7    3.0   4.0    0.0      2.0     0.0   \n",
       "4  473535    2008  75    50.0      7    3.0   5.0    0.0      1.0     0.0   \n",
       "\n",
       "     ...     B_ENDYEAR  branch_old  0_x_y  1_x_y  bra_1total  0_y_y  1_y_y  \\\n",
       "0    ...           0.0         0.0    0.0    0.0         0.0    0.0    0.0   \n",
       "1    ...           0.0         0.0    0.0    0.0         0.0    0.0    0.0   \n",
       "2    ...           0.0         0.0    0.0    0.0         0.0    0.0    0.0   \n",
       "3    ...           0.0         0.0    0.0    0.0         0.0    0.0    0.0   \n",
       "4    ...        2012.0         3.0    0.0    0.0         0.0    0.0    0.0   \n",
       "\n",
       "   bra_end_1total  bra_pro1  branh_if  \n",
       "0             0.0       0.0         0  \n",
       "1             0.0       0.0         0  \n",
       "2             0.0       0.0         0  \n",
       "3             0.0       0.0         0  \n",
       "4             0.0       0.0         1  \n",
       "\n",
       "[5 rows x 65 columns]"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#------------------------------------------------------------清洗&特征构造------------------------------------------------------#\n",
    "# 去重，此表无缺失值\n",
    "branch.drop_duplicates(inplace=True)\n",
    "# 子机构成立和倒闭年份的重要性\n",
    "branch['bra_end_year_imp'] = (1/(branch.B_REYEAR.max() - branch.B_REYEAR+1)).fillna(0)\n",
    "branch['bra_reyear_impor'] = (1/(branch.B_REYEAR.max() - branch.B_REYEAR+1)).fillna(0)\n",
    "\n",
    "# 计算子机构个数和停业比例\n",
    "branch_num = branch.groupby(['EID','IFHOME'],as_index=False).agg({'TYPECODE':'count'}).pivot('EID','IFHOME','TYPECODE').fillna(0)\n",
    "branch_num['bra_total'] = branch_num.apply(lambda x: x.sum(),axis=1)\n",
    "branch_end = branch.groupby(['EID','IFHOME'],as_index=False).agg({'B_ENDYEAR':'count'}).pivot('EID','IFHOME','B_ENDYEAR').fillna(0)\n",
    "branch_end['bra_end_total'] = branch_end.apply(lambda x: x.sum(),axis=1)\n",
    "branch_data = pd.merge(branch_num,branch_end,left_index=True,right_index=True,how='left')\n",
    "branch_data['bra_pro'] = np.where(branch_data['bra_total']>0,branch_data['bra_end_total']/branch_data['bra_total'],0)\n",
    "## 近一年\n",
    "# 是否最近两年(2015年)成立或倒闭\n",
    "branch['1year_be'] = np.where(branch.B_REYEAR>2013,1,0)\n",
    "branch['1year_end'] = np.where(branch.B_ENDYEAR>2013,1,0)\n",
    "branch_num1 = branch.groupby(['EID','IFHOME'],as_index=False).agg({'1year_be':'sum'}).pivot('EID','IFHOME','1year_be').fillna(0)\n",
    "branch_num1['bra_1total'] = branch_num1.apply(lambda x: x.sum(),axis=1)\n",
    "branch_end1 = branch.groupby(['EID','IFHOME'],as_index=False).agg({'1year_end':'sum'}).pivot('EID','IFHOME','1year_end').fillna(0)\n",
    "branch_end1['bra_end_1total'] = branch_end1.apply(lambda x: x.sum(),axis=1)\n",
    "branch_data1 = pd.merge(branch_num1,branch_end1,left_index=True,right_index=True,how='left')\n",
    "branch_data1['bra_pro1'] = np.where(branch_data1['bra_1total']>0,branch_data1['bra_end_1total']/branch_data1['bra_1total'],0)\n",
    "\n",
    "# 子机构成立的平均年份和关停的平均年份\n",
    "# 填充缺失值\n",
    "# branch['B_ENDYEAR'].fillna(2015,inplace=True)\n",
    "# 机构年龄影响\n",
    "branch['branch_old'] = branch.B_ENDYEAR - branch.B_REYEAR\n",
    "bran_avg_year = branch.groupby('EID').agg({'bra_end_year_imp':'sum','bra_reyear_impor':'sum','B_ENDYEAR':'mean','branch_old':'mean'})\n",
    "\n",
    "# bran_avg_year = np.rint(bran_avg_year)\n",
    "# 子机构关停与成立时间差，越小说明\n",
    "# bran_avg_year['branch_old'] = (bran_avg_year.B_ENDYEAR - bran_avg_year.B_REYEAR).fillna(0)\n",
    "branch_data = pd.merge(left=branch_data,right=bran_avg_year,left_index=True,right_index=True,how='left')\n",
    "# --------------------------------------------------------------合并------------------------------------------------------------------#\n",
    "branch_data.duplicated()\n",
    "data = pd.merge(left=data,right=branch_data,left_on='EID',right_index=True,how='left',sort=False).fillna(0)\n",
    "data = pd.merge(left=data,right=branch_data1,left_on='EID',right_index=True,how='left',sort=False).fillna(0)\n",
    "\n",
    "data['branh_if']= np.where(data.EID.isin(branch.EID),1,0)\n",
    "data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 企业权利信息"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>EID</th>\n",
       "      <th>RIGHTTYPE</th>\n",
       "      <th>TYPECODE</th>\n",
       "      <th>ASKDATE</th>\n",
       "      <th>FBDATE</th>\n",
       "      <th>ask_year</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>3102</td>\n",
       "      <td>20</td>\n",
       "      <td>pno13889</td>\n",
       "      <td>2010-11</td>\n",
       "      <td>2011-05</td>\n",
       "      <td>2010</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>3102</td>\n",
       "      <td>20</td>\n",
       "      <td>pno201544</td>\n",
       "      <td>2010-11</td>\n",
       "      <td>2011-05</td>\n",
       "      <td>2010</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3728</td>\n",
       "      <td>11</td>\n",
       "      <td>pno134933</td>\n",
       "      <td>2015-06</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2015</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3728</td>\n",
       "      <td>11</td>\n",
       "      <td>pno97198</td>\n",
       "      <td>2015-06</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2015</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>3728</td>\n",
       "      <td>11</td>\n",
       "      <td>pno97189</td>\n",
       "      <td>2015-06</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2015</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    EID  RIGHTTYPE   TYPECODE  ASKDATE   FBDATE  ask_year\n",
       "0  3102         20   pno13889  2010-11  2011-05      2010\n",
       "1  3102         20  pno201544  2010-11  2011-05      2010\n",
       "2  3728         11  pno134933  2015-06      NaN      2015\n",
       "3  3728         11   pno97198  2015-06      NaN      2015\n",
       "4  3728         11   pno97189  2015-06      NaN      2015"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# right = pd.read_csv('5right.csv',encoding='gb2312')\n",
    "right.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>EID</th>\n",
       "      <th>RGYEAR</th>\n",
       "      <th>HY</th>\n",
       "      <th>ZCZB</th>\n",
       "      <th>ETYPE</th>\n",
       "      <th>MPNUM</th>\n",
       "      <th>INUM</th>\n",
       "      <th>FINZB</th>\n",
       "      <th>FSTINUM</th>\n",
       "      <th>TZINUM</th>\n",
       "      <th>...</th>\n",
       "      <th>40_y</th>\n",
       "      <th>50_y</th>\n",
       "      <th>60_y</th>\n",
       "      <th>total2</th>\n",
       "      <th>GXB</th>\n",
       "      <th>cno</th>\n",
       "      <th>digit</th>\n",
       "      <th>mno</th>\n",
       "      <th>pno</th>\n",
       "      <th>right_year_imp</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>32741</td>\n",
       "      <td>2000</td>\n",
       "      <td>87</td>\n",
       "      <td>100.0</td>\n",
       "      <td>7</td>\n",
       "      <td>1.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>294220</td>\n",
       "      <td>2003</td>\n",
       "      <td>51</td>\n",
       "      <td>50.0</td>\n",
       "      <td>7</td>\n",
       "      <td>0.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.015385</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>10526</td>\n",
       "      <td>2013</td>\n",
       "      <td>75</td>\n",
       "      <td>100.0</td>\n",
       "      <td>7</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>237382</td>\n",
       "      <td>2014</td>\n",
       "      <td>75</td>\n",
       "      <td>9900.0</td>\n",
       "      <td>7</td>\n",
       "      <td>3.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>3.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.015385</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>473535</td>\n",
       "      <td>2008</td>\n",
       "      <td>75</td>\n",
       "      <td>50.0</td>\n",
       "      <td>7</td>\n",
       "      <td>3.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 88 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      EID  RGYEAR  HY    ZCZB  ETYPE  MPNUM  INUM  FINZB  FSTINUM  TZINUM  \\\n",
       "0   32741    2000  87   100.0      7    1.0   3.0    0.0      2.0     0.0   \n",
       "1  294220    2003  51    50.0      7    0.0   3.0    0.0      0.0     0.0   \n",
       "2   10526    2013  75   100.0      7    1.0   2.0    0.0      1.0     0.0   \n",
       "3  237382    2014  75  9900.0      7    3.0   4.0    0.0      2.0     0.0   \n",
       "4  473535    2008  75    50.0      7    3.0   5.0    0.0      1.0     0.0   \n",
       "\n",
       "        ...        40_y  50_y  60_y  total2  GXB  cno  digit  mno  pno  \\\n",
       "0       ...         0.0   0.0   0.0     0.0  0.0  0.0    0.0  0.0  0.0   \n",
       "1       ...         0.0   0.0   0.0     0.0  0.0  0.0    0.0  1.0  1.0   \n",
       "2       ...         0.0   0.0   0.0     0.0  0.0  0.0    0.0  0.0  0.0   \n",
       "3       ...         3.0   0.0   0.0     3.0  0.0  0.0    0.0  3.0  0.0   \n",
       "4       ...         0.0   0.0   0.0     0.0  0.0  0.0    0.0  0.0  0.0   \n",
       "\n",
       "   right_year_imp  \n",
       "0        0.000000  \n",
       "1        0.015385  \n",
       "2        0.000000  \n",
       "3        0.015385  \n",
       "4        0.000000  \n",
       "\n",
       "[5 rows x 88 columns]"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#---------------------------------------------------------数据清洗以及特征构造----------------------------------------------------#\n",
    "right['right_code']=right['TYPECODE'].apply(lambda x:x[:3] if x[0].isalpha() else  'digit')\n",
    "right['ask_year'] = right['ASKDATE'].apply(lambda x :x.split('-')[0]).astype('int')\n",
    "## ------------------------------------------------------------近一年--------------------------------------------------------------#\n",
    "# 是否最近两年(2014年)申请\n",
    "right['ask_2year'] = np.where(right.ask_year>2013,1,0)\n",
    "\n",
    "# 年份的重要性\n",
    "right['right_year_imp'] = 1/(1+right.ask_year.max() - right.ask_year.min())\n",
    "# 权利类型的数量\n",
    "right_num = right.groupby(['EID','RIGHTTYPE'],as_index=False).agg({'TYPECODE':'count'}).pivot('EID','RIGHTTYPE','TYPECODE').fillna(0)\n",
    "right_num['total'] = right_num.apply(lambda x :x.sum(),axis=1)\n",
    "# right_num.rename(columns={'11':'right_11','12':'right_12','20':'right_20','30':'right_30','40':'right_40','50':'right_50',\n",
    "#                           '60':'right_60'},inplace=True)\n",
    "right_num.rename(columns=lambda x : 'right_'+str(x))\n",
    "# ----------------------------------------------------------近两年权利类型---------------------------------------------------------#\n",
    "right_num2 = right.groupby(['EID','RIGHTTYPE'],as_index=False).agg({'ask_2year':'sum'}).pivot('EID','RIGHTTYPE','ask_2year').fillna(0)\n",
    "right_num2['total2'] = right_num2.apply(lambda x :x.sum(),axis=1)\n",
    "right_num2.rename(columns=lambda x : 'right_'+str(x))\n",
    "# 权利编码的数量\n",
    "right_code = pd.crosstab(right.EID,right.right_code)\n",
    "right_num['right_code_total'] = right_num.apply(lambda x :x.sum(),axis=1)\n",
    "\n",
    "# 年份求平均\n",
    "right_year = right.groupby('EID').agg({'right_year_imp':'mean'})\n",
    "# --------------------------------------------------------------合并------------------------------------------------------------------#\n",
    "data = pd.merge(left=data,right=right_num,left_on='EID',right_index=True,how='left')\n",
    "data = pd.merge(left=data,right=right_num2,left_on='EID',right_index=True,how='left')\n",
    "data = pd.merge(left=data,right=right_code,left_on='EID',right_index=True,how='left')\n",
    "data = pd.merge(left=data,right=right_year,left_on='EID',right_index=True,how='left')\n",
    "data.fillna(0,inplace=True)\n",
    "data.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 企业项目信息"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>EID</th>\n",
       "      <th>TYPECODE</th>\n",
       "      <th>DJDATE</th>\n",
       "      <th>IFHOME</th>\n",
       "      <th>pro_year</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>3273</td>\n",
       "      <td>5523256</td>\n",
       "      <td>2015-07</td>\n",
       "      <td>0</td>\n",
       "      <td>2015</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>3649</td>\n",
       "      <td>4073327</td>\n",
       "      <td>2014-03</td>\n",
       "      <td>1</td>\n",
       "      <td>2014</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>4253</td>\n",
       "      <td>4445461</td>\n",
       "      <td>2014-08</td>\n",
       "      <td>0</td>\n",
       "      <td>2014</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4595</td>\n",
       "      <td>3184459</td>\n",
       "      <td>2013-12</td>\n",
       "      <td>0</td>\n",
       "      <td>2013</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4595</td>\n",
       "      <td>3214578</td>\n",
       "      <td>2013-12</td>\n",
       "      <td>0</td>\n",
       "      <td>2013</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    EID  TYPECODE   DJDATE  IFHOME  pro_year\n",
       "0  3273   5523256  2015-07       0      2015\n",
       "1  3649   4073327  2014-03       1      2014\n",
       "2  4253   4445461  2014-08       0      2014\n",
       "3  4595   3184459  2013-12       0      2013\n",
       "4  4595   3214578  2013-12       0      2013"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# project = pd.read_csv('6project.csv',encoding='gb2312')\n",
    "project.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "project.drop_duplicates(inplace=True)\n",
    "project['pro_year'] = project['DJDATE'].apply(lambda x :x.split('-')[0]).astype('int')\n",
    "project['pro_1year'] = np.where(project['pro_year']>2014,1,0)\n",
    "project['pro_year_imp'] = 1/(2016 - project['pro_year'])\n",
    "project_data = project.groupby('EID').agg({'TYPECODE':'count','pro_year_imp':'sum','pro_1year':'sum'}).rename(columns={\"TYPECODE\":'pro_num',})\n",
    "data = pd.merge(left=data,right=project_data,left_on='EID',right_index=True,how='left')\n",
    "data.fillna(0,inplace=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "# 法律数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>EID</th>\n",
       "      <th>TYPECODE</th>\n",
       "      <th>LAWDATE</th>\n",
       "      <th>LAWAMOUNT</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>5986</td>\n",
       "      <td>104115771</td>\n",
       "      <td>2015-07-01</td>\n",
       "      <td>2700</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>5986</td>\n",
       "      <td>83486760</td>\n",
       "      <td>2014-06-01</td>\n",
       "      <td>88500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>5986</td>\n",
       "      <td>76450675</td>\n",
       "      <td>2014-02-01</td>\n",
       "      <td>1202100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>5986</td>\n",
       "      <td>97776391</td>\n",
       "      <td>2014-06-01</td>\n",
       "      <td>88500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5986</td>\n",
       "      <td>85054730</td>\n",
       "      <td>2014-02-01</td>\n",
       "      <td>1202100</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    EID   TYPECODE     LAWDATE  LAWAMOUNT\n",
       "0  5986  104115771  2015-07-01       2700\n",
       "1  5986   83486760  2014-06-01      88500\n",
       "2  5986   76450675  2014-02-01    1202100\n",
       "3  5986   97776391  2014-06-01      88500\n",
       "4  5986   85054730  2014-02-01    1202100"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# lawsuit = pd.read_csv('7lawsuit.csv',encoding='gb2312')\n",
    "lawsuit.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "lawsuit.drop_duplicates(inplace=True)\n",
    "lawsuit['law_year']=lawsuit['LAWDATE'].apply(lambda x :x.split('-')[0]).astype('int')\n",
    "lawsuit['law_1year'] = np.where(lawsuit['law_year']>2014,1,0)\n",
    "lawsuit['law_year_imp'] = 1/(2016 - lawsuit['law_year'])\n",
    "lawsuit['law_wei'] =  lawsuit['LAWAMOUNT']*lawsuit['law_year_imp']\n",
    "\n",
    "lawsuit_data = lawsuit.groupby('EID').agg({'TYPECODE':'count','LAWAMOUNT':'sum','law_year_imp':'sum','law_1year':'sum',\n",
    "                                           'law_wei':'sum'}).rename(columns={\"TYPECODE\":'law_num'})\n",
    "# lawsuit_data.head()\n",
    "data = pd.merge(left=data,right=lawsuit_data,left_on='EID',right_index=True,how='left')\n",
    "data.fillna(0,inplace=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 失信数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False    3657\n",
       "dtype: int64"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# breakfaith.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "breakfaith['break_year'] = breakfaith['FBDATE'].apply(lambda x :x.split('/')[0]).astype('int')\n",
    "breakfaith['break_year_imp'] = 1/(2016 - breakfaith['break_year'])\n",
    "breakfaith['break_1year'] = np.where(breakfaith['break_year']>2014,1,0)\n",
    "breakfaith_data = breakfaith.groupby('EID').agg({'TYPECODE':'count','break_year_imp':'sum','break_1year':'sum',\n",
    "                                                }).rename(columns={\"TYPECODE\":'break_num'})\n",
    "data = pd.merge(left=data,right=breakfaith_data,left_on='EID',right_index=True,how='left')\n",
    "data.fillna(0,inplace=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 招聘信息数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>EID</th>\n",
       "      <th>WZCODE</th>\n",
       "      <th>RECRNUM</th>\n",
       "      <th>RECDATE</th>\n",
       "      <th>re_year</th>\n",
       "      <th>re_month</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1382</td>\n",
       "      <td>ZP02</td>\n",
       "      <td>8.0</td>\n",
       "      <td>2015-08</td>\n",
       "      <td>2015</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2480</td>\n",
       "      <td>ZP02</td>\n",
       "      <td>2124.0</td>\n",
       "      <td>2015-08</td>\n",
       "      <td>2015</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3324</td>\n",
       "      <td>ZP02</td>\n",
       "      <td>15.0</td>\n",
       "      <td>2015-08</td>\n",
       "      <td>2015</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>3324</td>\n",
       "      <td>ZP03</td>\n",
       "      <td>10.0</td>\n",
       "      <td>2015-08</td>\n",
       "      <td>2015</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>3529</td>\n",
       "      <td>ZP03</td>\n",
       "      <td>23.0</td>\n",
       "      <td>2015-08</td>\n",
       "      <td>2015</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    EID WZCODE  RECRNUM  RECDATE  re_year  re_month\n",
       "0  1382   ZP02      8.0  2015-08     2015         8\n",
       "1  2480   ZP02   2124.0  2015-08     2015         8\n",
       "3  3324   ZP02     15.0  2015-08     2015         8\n",
       "4  3324   ZP03     10.0  2015-08     2015         8\n",
       "5  3529   ZP03     23.0  2015-08     2015         8"
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "recruit[recruit['re_month']==8].head()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>EID</th>\n",
       "      <th>RGYEAR</th>\n",
       "      <th>HY</th>\n",
       "      <th>ZCZB</th>\n",
       "      <th>ETYPE</th>\n",
       "      <th>MPNUM</th>\n",
       "      <th>INUM</th>\n",
       "      <th>FINZB</th>\n",
       "      <th>FSTINUM</th>\n",
       "      <th>TZINUM</th>\n",
       "      <th>...</th>\n",
       "      <th>law_1year</th>\n",
       "      <th>law_wei</th>\n",
       "      <th>break_num</th>\n",
       "      <th>break_year_imp</th>\n",
       "      <th>break_1year</th>\n",
       "      <th>ZP01</th>\n",
       "      <th>ZP02</th>\n",
       "      <th>ZP03</th>\n",
       "      <th>recruit_tot</th>\n",
       "      <th>re_month</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>32741</td>\n",
       "      <td>2000</td>\n",
       "      <td>87</td>\n",
       "      <td>100.0</td>\n",
       "      <td>7</td>\n",
       "      <td>1.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>-5.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>294220</td>\n",
       "      <td>2003</td>\n",
       "      <td>51</td>\n",
       "      <td>50.0</td>\n",
       "      <td>7</td>\n",
       "      <td>0.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>-5.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>10526</td>\n",
       "      <td>2013</td>\n",
       "      <td>75</td>\n",
       "      <td>100.0</td>\n",
       "      <td>7</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>-5.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>237382</td>\n",
       "      <td>2014</td>\n",
       "      <td>75</td>\n",
       "      <td>9900.0</td>\n",
       "      <td>7</td>\n",
       "      <td>3.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>-5.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>473535</td>\n",
       "      <td>2008</td>\n",
       "      <td>75</td>\n",
       "      <td>50.0</td>\n",
       "      <td>7</td>\n",
       "      <td>3.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>-5.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 104 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      EID  RGYEAR  HY    ZCZB  ETYPE  MPNUM  INUM  FINZB  FSTINUM  TZINUM  \\\n",
       "0   32741    2000  87   100.0      7    1.0   3.0    0.0      2.0     0.0   \n",
       "1  294220    2003  51    50.0      7    0.0   3.0    0.0      0.0     0.0   \n",
       "2   10526    2013  75   100.0      7    1.0   2.0    0.0      1.0     0.0   \n",
       "3  237382    2014  75  9900.0      7    3.0   4.0    0.0      2.0     0.0   \n",
       "4  473535    2008  75    50.0      7    3.0   5.0    0.0      1.0     0.0   \n",
       "\n",
       "     ...     law_1year  law_wei  break_num  break_year_imp  break_1year  ZP01  \\\n",
       "0    ...           0.0      0.0        0.0             0.0          0.0   0.0   \n",
       "1    ...           0.0      0.0        0.0             0.0          0.0   0.0   \n",
       "2    ...           0.0      0.0        0.0             0.0          0.0   0.0   \n",
       "3    ...           0.0      0.0        0.0             0.0          0.0   0.0   \n",
       "4    ...           0.0      0.0        0.0             0.0          0.0   0.0   \n",
       "\n",
       "   ZP02  ZP03  recruit_tot  re_month  \n",
       "0   0.0   0.0          0.0      -5.0  \n",
       "1   0.0   0.0          0.0      -5.0  \n",
       "2   0.0   0.0          0.0      -5.0  \n",
       "3   0.0   0.0          0.0      -5.0  \n",
       "4   0.0   0.0          0.0      -5.0  \n",
       "\n",
       "[5 rows x 104 columns]"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "recruit['re_year'] = recruit['RECDATE'].apply(lambda x :x.split('-')[0]).astype('int')\n",
    "recruit['re_month'] = recruit['RECDATE'].apply(lambda x :x.split('-')[1]).astype('int')\n",
    "recruit['re_month'] = np.where(recruit.re_year == 2014,recruit.re_month-12,recruit.re_month)\n",
    "recruit_num = recruit.groupby(['EID','WZCODE'],as_index=False).agg({'RECRNUM':'sum'}).pivot('EID','WZCODE','RECRNUM').fillna(0)\n",
    "recruit_num['recruit_tot'] = recruit_num.apply(lambda x :x.sum(),axis=1)\n",
    "recruit_month = recruit.groupby('EID')['re_month'].max()\n",
    "# --------------------------------------------------------------合并------------------------------------------------------------------#\n",
    "data = pd.merge(left=data,right=recruit_num,left_on='EID',right_index=True,how='left').fillna(0)\n",
    "data = pd.merge(left=data,right=pd.DataFrame(recruit_month),left_on='EID',right_index=True,how='left').fillna(-5)\n",
    "data.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 投资企业信息"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 106,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "data.to_csv('data.csv',index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>EID</th>\n",
       "      <th>RGYEAR</th>\n",
       "      <th>HY</th>\n",
       "      <th>ZCZB</th>\n",
       "      <th>ETYPE</th>\n",
       "      <th>MPNUM</th>\n",
       "      <th>INUM</th>\n",
       "      <th>FINZB</th>\n",
       "      <th>FSTINUM</th>\n",
       "      <th>TZINUM</th>\n",
       "      <th>...</th>\n",
       "      <th>inv_ZP03</th>\n",
       "      <th>inv_recruit_tot</th>\n",
       "      <th>inv_re_month</th>\n",
       "      <th>inv_ZB_pro</th>\n",
       "      <th>inv_dificit</th>\n",
       "      <th>inv_end_if</th>\n",
       "      <th>inv_endyear_impor</th>\n",
       "      <th>inv_dif_wei</th>\n",
       "      <th>BTEID</th>\n",
       "      <th>invest_if</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>32741</td>\n",
       "      <td>2000</td>\n",
       "      <td>87</td>\n",
       "      <td>100.0</td>\n",
       "      <td>7</td>\n",
       "      <td>1.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>-20.0</td>\n",
       "      <td>250.0</td>\n",
       "      <td>250.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>0.168155</td>\n",
       "      <td>0.124008</td>\n",
       "      <td>4.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>294220</td>\n",
       "      <td>2003</td>\n",
       "      <td>51</td>\n",
       "      <td>50.0</td>\n",
       "      <td>7</td>\n",
       "      <td>0.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>10526</td>\n",
       "      <td>2013</td>\n",
       "      <td>75</td>\n",
       "      <td>100.0</td>\n",
       "      <td>7</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>237382</td>\n",
       "      <td>2014</td>\n",
       "      <td>75</td>\n",
       "      <td>9900.0</td>\n",
       "      <td>7</td>\n",
       "      <td>3.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>473535</td>\n",
       "      <td>2008</td>\n",
       "      <td>75</td>\n",
       "      <td>50.0</td>\n",
       "      <td>7</td>\n",
       "      <td>3.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 207 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      EID  RGYEAR  HY    ZCZB  ETYPE  MPNUM  INUM  FINZB  FSTINUM  TZINUM  \\\n",
       "0   32741    2000  87   100.0      7    1.0   3.0    0.0      2.0     0.0   \n",
       "1  294220    2003  51    50.0      7    0.0   3.0    0.0      0.0     0.0   \n",
       "2   10526    2013  75   100.0      7    1.0   2.0    0.0      1.0     0.0   \n",
       "3  237382    2014  75  9900.0      7    3.0   4.0    0.0      2.0     0.0   \n",
       "4  473535    2008  75    50.0      7    3.0   5.0    0.0      1.0     0.0   \n",
       "\n",
       "     ...      inv_ZP03  inv_recruit_tot  inv_re_month  inv_ZB_pro  \\\n",
       "0    ...           0.0              0.0         -20.0       250.0   \n",
       "1    ...           0.0              0.0           0.0         0.0   \n",
       "2    ...           0.0              0.0           0.0         0.0   \n",
       "3    ...           0.0              0.0           0.0         0.0   \n",
       "4    ...           0.0              0.0           0.0         0.0   \n",
       "\n",
       "   inv_dificit  inv_end_if  inv_endyear_impor  inv_dif_wei  BTEID  invest_if  \n",
       "0        250.0         4.0           0.168155     0.124008    4.0          1  \n",
       "1          0.0         0.0           0.000000     0.000000    0.0          0  \n",
       "2          0.0         0.0           0.000000     0.000000    0.0          0  \n",
       "3          0.0         0.0           0.000000     0.000000    0.0          0  \n",
       "4          0.0         0.0           0.000000     0.000000    0.0          0  \n",
       "\n",
       "[5 rows x 207 columns]"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 基本信息\n",
    "invest_data = pd.merge(invest,entbase,left_on='BTEID',right_on='EID',how='left')\n",
    "del(invest_data['EID_y'])\n",
    "del(invest_data['RGYEAR'])\n",
    "# 合并\n",
    "# 资本变动的表\n",
    "invest_data = pd.merge(left=invest_data,right=alter_5,left_on='BTEID',right_on='EID',how='left')\n",
    "del(invest_data['EID'])\n",
    "\n",
    "# 变动数量的表\n",
    "invest_data = pd.merge(left=invest_data,right=alter_num,left_on='BTEID',right_index=True,how='left').fillna(0)\n",
    "invest_data = pd.merge(left=invest_data,right=alter_num1,left_on='BTEID',right_index=True,how='left').fillna(0)\n",
    "# 原始资本表\n",
    "invest_data = pd.merge(left=invest_data,right=alter_ori_zb,left_on='BTEID',right_on='EID',how='left')\n",
    "del(invest_data['EID'])\n",
    "\n",
    "# 分支机构\n",
    "invest_data = pd.merge(left=invest_data,right=branch_data,left_on='BTEID',right_index=True,how='left',sort=False)\n",
    "invest_data = pd.merge(left=invest_data,right=branch_data1,left_on='BTEID',right_index=True,how='left',sort=False)\n",
    "\n",
    "# 权利\n",
    "invest_data = pd.merge(left=invest_data,right=right_num,left_on='BTEID',right_index=True,how='left')\n",
    "invest_data = pd.merge(left=invest_data,right=right_code,left_on='BTEID',right_index=True,how='left')\n",
    "invest_data = pd.merge(left=invest_data,right=right_year,left_on='BTEID',right_index=True,how='left')\n",
    "invest_data = pd.merge(left=invest_data,right=right_num2,left_on='BTEID',right_index=True,how='left')\n",
    "\n",
    "# 项目\n",
    "invest_data = pd.merge(left=invest_data,right=project_data,left_on='BTEID',right_index=True,how='left')\n",
    "\n",
    "# 招聘\n",
    "invest_data = pd.merge(left=invest_data,right=recruit_num,left_on='BTEID',right_index=True,how='left').fillna(0)\n",
    "invest_data = pd.merge(left=invest_data,right=pd.DataFrame(recruit_month),left_on='BTEID',right_index=True,how='left').fillna(-5)\n",
    "\n",
    "# 注册资本比例\n",
    "invest_data['ZCZB'].fillna(entbase.EID.mean(),inplace=True)\n",
    "invest_data['ZB_pro'] = invest_data.BTBL * invest_data.ZCZB\n",
    "# 亏损的钱\n",
    "invest_data['dificit'] = np.where(invest_data.BTENDYEAR.isnull(),0,invest_data['ZB_pro'])\n",
    "# 是否倒闭\n",
    "invest_data['end_if'] = np.where(invest_data.BTENDYEAR.isnull(),0,1)\n",
    "# 倒闭年限的权重，取倒数\n",
    "invest_data['endyear_impor'] = (1/(2016 - invest_data.BTENDYEAR)).fillna(0)\n",
    "# 亏损的钱的加权\n",
    "invest_data['dif_wei'] = invest_data['dificit'] * invest_data['endyear_impor']\n",
    "invest_data.fillna(0,inplace=True)\n",
    "invest_num = invest_data.groupby('EID_x').agg({'BTEID':'count'})\n",
    "invest_data = invest_data.drop(labels=['BTEID'],axis=1)\n",
    "invest_data = invest_data.groupby('EID_x').sum()\n",
    "invest_data.rename(columns=lambda x:'inv_'+str(x),inplace=True)\n",
    "data = pd.merge(data,invest_data,left_on='EID',right_index=True,how='left')\n",
    "data = pd.merge(data,invest_num,left_on='EID',right_index=True,how='left')\n",
    "data.fillna(0,inplace=True)\n",
    "data['invest_if'] = np.where(data.EID.isin(invest.EID),1,0)\n",
    "data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# invest_data.groupby('EID_x').sum().describe()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 数据集保存到本地"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# 保存训练集\n",
    "train = pd.read_csv('train.csv',encoding='gb2312')\n",
    "data_train = pd.merge(left=train,right=data,left_on='EID',right_on='EID',how='left')\n",
    "data_train.to_csv('data_train.csv',index=False)\n",
    "# 测试集\n",
    "eva = pd.read_csv('evaluation_public.csv',encoding='gb2312')\n",
    "data_test = pd.merge(left=eva,right=data,left_on='EID',right_on='EID',how='left')\n",
    "data_test.to_csv('data_test.csv',index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "eva = pd.read_csv('evaluation_public.csv',encoding='gb2312')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
